"""
@-*- coding: utf-8 -*-
@ python: 3.12.3
@ 创建者: JacksonCode
@ 创建时间: 2025-10-13
"""
# sm2 sm3 sm4
import base64
from gmssl import sm2

private_key = "00B9AB0B828FF68872F21A837FC303668428DEA11DCD1B24429D0C99E24EED83D5"
public_key = "B9C9A6E04E9C91F7BA880429273747D7EF5DDEB0BB2FF6317EB00BEF331A83081A6994B8993F3F5D6EADDDB81872266C87C018FB4162F5AF347B483E24620207"
sm2_crypt = sm2.CryptSM2(public_key=public_key, private_key=private_key)

data = "123456"
enc_data = sm2_crypt.encrypt(data.encode('utf-8'))
print(enc_data)
dec_data = sm2_crypt.decrypt(enc_data)
print(dec_data.decode())

from gmssl.sm4 import CryptSM4, SM4_ENCRYPT, SM4_DECRYPT
import base64

key = b'3l5butlj26hvv313'
value = b'123456'  # bytes类型
iv = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'  # bytes类型
crypt_sm4 = CryptSM4()

crypt_sm4.set_key(key, SM4_ENCRYPT)
encrypt_value = crypt_sm4.crypt_ecb(value)  # bytes类型
print(base64.b64encode(encrypt_value.hex().encode()).decode())
crypt_sm4.set_key(key, SM4_DECRYPT)
decrypt_value = crypt_sm4.crypt_ecb(encrypt_value)  # bytes类型
print(decrypt_value.decode())
# assert value == decrypt_value

from gmssl import sm3, func

e = func.bytes_to_list('123456'.encode())
r = sm3.sm3_hash(e)
print(r)
# 207cf410532f92a47dee245ce9b11ff71f578ebd763eb3bbea44ebd043d018fb
